package com.shj.em.biz.prod.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.shj.em.biz.prod.entity.Knife;
import com.shj.em.biz.prod.mapper.KnifeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;


/**
 * 刀具表 服务实现类
 *
 * @author Shen Huang Jian
 * @since 2018-12-16
 */
@Service
@Transactional
public class KnifeServiceImpl extends ServiceImpl<KnifeMapper, Knife> implements KnifeService {

    @Autowired
    KnifeMapper knifeMapper;

    public Page<Knife> queryKnifePage(Map<String, Object> params){
        int offset = (Integer)params.get("offset");
        int pageSize = (Integer)params.get("limit");
        int pageNo = offset / pageSize + 1;
        Page<Knife> page = new Page(pageNo, pageSize);
        List<Knife> list = knifeMapper.queryKnifePage(page, params);
        return page.setRecords(list);
    }

    public List<Knife> findKnifeByCncId(Long cncId){
        Wrapper<Knife> wrapper = new EntityWrapper<>();
        wrapper.eq("cnc_id", cncId);
        return knifeMapper.selectList(wrapper);
    }
}
